﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .buttonimg {
            background: url("../gq_moblie/images/button.png") no-repeat;
        }

            .buttonimg:hover {
                background: url("../gq_moblie/images/button_hover.png") no-repeat;
                background-size: 100%;
            }

        .buttonimg2 {
            background: url("../gq_moblie/images/button2.png") no-repeat;
        }
    </style>
    <link rel="stylesheet" href="./css/style.css">
    <script src="./js/flexible.min.js"></script>
</head>

<body>



    <div class="web_container">

        <div class="web_headerBlock">

            <div class="logo">
                <a href=""></a>
            </div>

            <div class="lie"></div>

            <div class="nav">
                <div class="lis"><a href="">White Paper</a></div>
                <div class="lis"><a href="">Contact</a></div>
                <div class="lis"><a href="">Discord</a></div>
                <div class="lis"><a href="">Telegram</a></div>
            </div>

            <div class="mesk"></div>

        </div>

        <div class="web_searchBlock">
            <div class="web_searchBlock_bar">
                <div class="left"><input type="text" id="ercAddress" maxlength="80" placeholder="Enter Your Erc20 Wallet Address" /></div>
                <div class="right"><div id="submit" class="button buttonimg">Submit</div></div>
            </div>
        </div>


        <div class="web_popleNumberBlock">
            <div class="lis">保存成功，分享您的地址获得更多奖励: http://smartx.one/water/123</div>
            <div class="lis">
                <span class="cx"><a href="javascript:goList()">查询奖励记录</a></span>
            </div>
        </div>


        <div id="content" class="web_contentBlock">

            <div class="content">
                <div class="lis_line-height">
                    <div>当前共有<i id="userNum" class="red">0</i>人参与活动</div>
                    <div>您今日累积点击量: <i id="touchNum" class="red">0</i></div>
                </div>

            </div>

        </div>


        <div class="web_footer">2019 SmartX.inc</div>


    </div>
    <div>
        <!--<input type="hidden" id="userid" value="" />-->
    </div>

</body>
</html>
<script src="config.js"></script>
<script src="js/jquery-3.3.1.js"></script>
<script>
    let server = apiServer();
    let userid = "";
    let token = "";
    $(function () {
        pageInit();
        getTouchInit();
        $("#submit").click(submit);
        $("#content").click(addTouch);
    });

    function goList() {
        var url = location.href;
        url = url.substr(url.lastIndexOf('?'));
        if (url != "l" || url > 5) {
            url = "list.html" + url;
        }
        else {
            url = "list.html";
        }
        location.href = url;
    }

    function pageInit() {
        var obj = GetRequest();
        userid = obj.userid;
        token = obj.token;

        if (token) {
            $("#submit").removeClass("buttonimg");
            $("#submit").addClass("buttonimg2");
        }
    }


    //获取url中的参数
    function GetRequest() {
        var url = location.href;
        url = url.substr(url.lastIndexOf('?'));

        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    function setUrl(url) {
        var stateObject = {};
        var title = "Wow Title";
        var newUrl = url;
        history.pushState(stateObject, title, newUrl);
    }

    function getTouchInit() {
        $.ajax({
            url: server + "/api/ShuiLongTou/GetTouchInit",
            type: "POST",
            dataType: "json",
            data: {
                "Source": "11"
            },
            success: function (data) {
                if (data && data.Code == 0) {
                    $("#userNum").text(data.Data.UserCount);
                    $("#touchNum").text(data.Data.TouchCount);
                }
            }
        });
    }

    //校验必须是字母和数字
    function checkErcForm(str) {
        return /^[\da-z]+$/i.test(str);
    }

    function submit() {
        //userid = $("#userid").val();
        if (userid) {
            //alert("已经登陆");
            return false;
        }

        var ercAddress = $("#ercAddress").val();
        if (!ercAddress) {
            alert("请输入ERC地址");
            return false;
        }

        if (!checkErcForm(ercAddress)) {
            alert("请检查ERC地址格式是否正确");
            return false;
        }

        if (ercAddress.length > 80) {
            alert("请检查ERC地址格式是否正确");
            return false;
        }

        //erc格式不正确
        //if (ercAddress.length != 64) {
        //    return false;
        //}

        $.ajax({
            url: server + "/api/ShuiLongTou/CreateUserSLT",
            type: "POST",
            dataType: "json",
            data: {
                "Source": "11",
                "ERCAddress": ercAddress,
            },
            //error: function (XmlHttpRequest, textStatus, errorThrown) { alert(XmlHttpRequest.responseText); },
            success: function (data) {
                if (data && (data.Code == 0 || data.Code == 1)) {
                    alert("加入成功，可以点击下面区域了");//登陆成功
                    token = data.Data.Token;
                    userid = data.Data.UserID;
                    $("#userNum").text(data.Data.UserCount);
                    $("#touchNum").text(data.Data.TouchCount);

                    //$("#userid").val(data.Data.UserID);
                    $("#submit").removeClass("buttonimg");
                    $("#submit").addClass("buttonimg2");
                    //不保存cookie,定位到url
                    var url = "index.html?userid=" + data.Data.UserID + "&token=" + data.Data.Token + "";
                    setUrl(url);
                }
                else {
                    alert("提交失败，" + data.Msg);
                }
            }
        });
    }

    function addTouch() {
        if (!userid) {
            //alert("请先登陆");
            return false;
        }
        $.ajax({
            url: server + "/api/ShuiLongTou/AddShuiLongTou",
            type: "POST",
            dataType: "json",
            data: {
                "Source": "11",
                "Token": token,
            },
            success: function (data) {
                if (data && data.Code == 0) {
                    token = data.Data.Token;
                    $("#userNum").text(data.Data.UserCount);
                    $("#touchNum").text(data.Data.TouchCount);
                }
                else {
                    alert("提交失败，" + data.Msg);
                }
            }
        });
    }


    $(window).resize(function () {
        if (document.body.clientWidth > 1000) {
            $('.nav').show();
        } else {
            $('.nav').hide();
            $('.mesk').hide();
        }
    })

    if (document.body.clientWidth > 1000) {
        $('.nav').show();
    } else {
        $('.nav').hide();
        $('.mesk').hide();
    }

    $('body').on('click', '.lie', function () {
        $('.nav').show();
        $('.mesk').show();
        $('body').css({ 'overflow-y': 'hidden' });
    })

    $('body').on('click', '.mesk', function () {
        $('.nav').hide();
        $('.mesk').hide();
        $('body').css({ 'overflow-y': '' });
    })

</script>
